package view;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import controller.AddUser;

@SuppressWarnings("serial")
public class Panelregister extends JPanel {

	private static Panelregister single;

	private JLabel formName = new JLabel("Registratie formulier");
	private JLabel name = new JLabel("* Gebruikers naam: ");
	private JLabel password = new JLabel("* Wachtwoord: ");

	private JLabel confirmPassword = new JLabel("* Bevestig wachtwoord: ");
	private JLabel required = new JLabel("Alle velden zijn verplicht");

	private JTextField nameField = new JTextField();
	private JPasswordField passwordField = new JPasswordField();
	private JPasswordField confirmPassField = new JPasswordField();

	private JButton confirmButton = new JButton("Opslaan");
	private JButton cancelButton = new JButton("Annuleren");

	private Font font = new Font("Serif", Font.BOLD, 16);

	public Panelregister() {

		setBounds(0, 0, 860, 720);
		setLayout(null);

		formName.setBounds(70, 40, 400, 30);
		formName.setFont(font);

		name.setBounds(70, 150, 200, 30);

		password.setBounds(70, 200, 200, 30);
		confirmPassword.setBounds(70, 250, 200, 30);
		required.setBounds(70, 400, 200, 30);

		nameField.setBounds(300, 150, 200, 30);

		passwordField.setBounds(300, 200, 200, 30);
		confirmPassField.setBounds(300, 250, 200, 30);

		confirmButton.setBounds(300, 325, 100, 30);
		confirmButton.setActionCommand("Opslaan");
		confirmButton.addActionListener(new AddUser(this));
		cancelButton.setBounds(400, 325, 100, 30);
		cancelButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				PanelHolder mf = PanelHolder.getInstance();
				mf.remove(Panelregister.getInstance());
				mf.add(PanelUserList.getInstance());
				mf.repaint();
				mf.validate();
			}
		});

		add(formName);
		add(name);
		add(password);
		add(confirmPassword);
		add(required);
		add(nameField);
		add(confirmButton);
		add(cancelButton);
		add(passwordField);
		add(confirmPassField);

	}

	public static Panelregister getInstance() {
		if (single == null) {
			single = new Panelregister();
		}
		return single;
	}

	public static void selfDestroy() {
		single = null;
	}

	public JLabel getFormName() {
		return formName;
	}

	public void setFormName(JLabel formName) {
		this.formName = formName;
	}

	public JLabel getPassword() {
		return password;
	}

	public void setPassword(JLabel password) {
		this.password = password;
	}

	public JLabel getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(JLabel confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public JTextField getNameField() {
		return nameField;
	}

	public void setNameField(JTextField nameField) {
		this.nameField = nameField;
	}

	public JPasswordField getPasswordField() {
		return passwordField;
	}

	public void setPasswordField(JPasswordField passwordField) {
		this.passwordField = passwordField;
	}

	public JPasswordField getConfirmPassField() {
		return confirmPassField;
	}

	public void setConfirmPassField(JPasswordField confirmPassField) {
		this.confirmPassField = confirmPassField;
	}

	public JButton getConfirmButton() {
		return confirmButton;
	}

	public void setConfirmButton(JButton confirmButton) {
		this.confirmButton = confirmButton;
	}

	public JButton getResetButton() {
		return cancelButton;
	}

	public void setResetButton(JButton resetButton) {
		this.cancelButton = resetButton;
	}

	public void setName(JLabel name) {
		this.name = name;
	}

	public JButton getCancelButton() {
		return cancelButton;
	}

	public void setCancelButton(JButton cancelButton) {
		this.cancelButton = cancelButton;
	}

}
